Log patron authorization identifier in uwsgi access logs#3146
Log patron authorization identifier in uwsgi access logs#3146jonathangreen wants to merge 1 commit intomainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3146 +/- ##
==========================================
- Coverage 93.26% 93.26% -0.01%
==========================================
Files 493 493
Lines 45586 45599 +13
Branches 6252 6254 +2
==========================================
+ Hits 42518 42530 +12
Misses 1982 1982
- Partials 1086 1087 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code reviewFound 1 issue:
circulation/src/palace/manager/api/controller/base.py Lines 67 to 82 in 05f159b circulation/docker/services/uwsgi/uwsgi.d/40_log.ini Lines 1 to 4 in 05f159b |
05f159b to
bf67eaf
Compare
|
Hi @lgcassab, thanks for this review! You're spot on, the issue you flagged is exactly what I found during integration testing. If you look at the subsequent commits, I've made many of your suggested changes. I also added sanitization for log injection since uwsgi doesn't escape logvar values at all (control characters, spaces, etc.). After all these changes, I've put this PR into draft, since I'd like to do a bit more testing, and I'm not sure if I want to merge this one, given the relatively small gain of information in log messages vs the amount of code we need here once you factor in sanitization and non-uwsgi use cases. Out of curiosity, do you use Palace Manager? I don't think I've seen your name around here before. |
a37067b to
89c4c60
Compare
Set an AUTHORIZATION_IDENTIFIER uwsgi logvar during patron authentication so the authenticated user appears in access logs. The logvar is set early in the auth flow (from basic auth username) to capture failed attempts, then overwritten with the patron's canonical authorization_identifier on success. Values are sanitized to prevent log injection.
022b2e4 to
28d39fa
Compare
|
This is more complicated then my first pass, but I've wanted this to be able to cross reference logs a few times in the past, so I think its worth bringing in. I did a bunch of testing with uwsgi in docker to make sure this is working, and logs are being escaped as expected. @tdilauro I re-requested another review on this, since its changed a fair bit from your first look at it. |
tdilauro
left a comment
There was a problem hiding this comment.
Oof. They don't make it easy, do they.
Description
Sets a uwsgi logvar (
AUTHORIZATION_IDENTIFIER) during patron authentication and updates the uwsgi log format to include it. This makes the patron identifier (library card barcode) visible in uwsgi access logs, aiding in troubleshooting authentication issues.AUTHORIZATION_IDENTIFIERto the submitted username before authentication, so it appears in logs even on failed 401 requestspatron.authorization_identifier, which may differ from the submitted usernameAUTHORIZATION_IDENTIFIERfrompatron.authorization_identifierafter successful authenticationstr.translate()to prevent log injection (control characters, spaces, and double quotes are escaped as\xHH)Motivation and Context
This would have helped while troubleshooting CM authentication errors. Without the patron identifier in access logs, it's difficult to correlate failed requests to specific patrons when investigating issues.
How Has This Been Tested?
AUTHORIZATION_IDENTIFIERlogvar behavior covering basic auth (success and failure) and non-basic auth flowsChecklist